﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Telerik.Web.UI;

namespace EXAM.Admin.Page_Admin.Windows
{
    public partial class FrmSetValueFilter : System.Web.UI.Page
    {
        string sErr = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            //if (Session["currentdtb"] != null)
            //    "EXA" = "EXA";
            Format_DatePicker("EXA", ref dpTo);
            Format_DatePicker("EXA", ref dpFrom);
            FormatNumbericTextBox("EXA", ref numFrom);
            FormatNumbericTextBox("EXA", ref numTo);
        }

        private void FormatNumbericTextBox(string dtb, ref Telerik.Web.UI.RadNumericTextBox ctrl)
        {
            ctrl.Culture = new System.Globalization.CultureInfo("En-us");
            //BUS.DBAControl control = new BUS.DBAControl();
            //DTO.DBAInfo info = control.Get("EXA", ref sErr);
            ctrl.NumberFormat.DecimalDigits = 2;
        }
        public void Format_DatePicker(string dtb, ref RadDatePicker dp)
        {
            dp.Culture = new System.Globalization.CultureInfo("En-us");
        }

        protected void btnReload_Click(object sender, EventArgs e)
        {
            if (hdCode.Value != "" && Session["sqlbuilder"] != null)
            {
                QueryBuilder.SQLBuilder _sqlBuilder = (QueryBuilder.SQLBuilder)Session["sqlbuilder"];
                foreach (QueryBuilder.Filter x in _sqlBuilder.Filters)
                {
                    if (x.Code.Trim() == hdCode.Value.Trim())
                    {
                        hdType.Value = x.Node.FType.Trim();
                        if (x.Node.FType.Trim() != "")
                        {
                            if (x.Node.FType.Substring(0, 1).Trim() == "N")
                            {
                                numFrom.Visible = true;
                                numTo.Visible = true;
                                Double from, to;
                                Double.TryParse(x.ValueFrom, out from);
                                Double.TryParse(x.ValueTo, out to);
                                numFrom.Value = from;
                                numTo.Value = to;
                            }
                            else if (x.Node.FType.Trim() == "SDN")
                            {
                                dpFrom.Visible = true;
                                dpTo.Visible = true;
                                int from = 0, to = 0;
                                Int32.TryParse(x.ValueFrom, out from);
                                Int32.TryParse(x.ValueTo, out to);
                                dpFrom.SelectedDate = BUS.CommonControl.ConvertIntToDate(from);
                                dpTo.SelectedDate = BUS.CommonControl.ConvertIntToDate(to);
                            }
                            else if (x.Node.FType.Trim() == "SPN")
                            {
                                numFrom.Visible = true;
                                numFrom.MaxLength = 7;
                                numFrom.NumberFormat.DecimalDigits = 0;
                                numFrom.NumberFormat.GroupSeparator = "";
                                numTo.Visible = true;
                                numTo.MaxLength = 7;
                                numTo.NumberFormat.DecimalDigits = 0;
                                numTo.NumberFormat.GroupSeparator = "";
                                numFrom.Value = Convert.ToDouble(x.ValueFrom);
                                numTo.Value = Convert.ToDouble(x.ValueTo);
                                lbFrom.Text = "YYYYMMM";
                                lbTo.Text = "YYYYMMM";
                            }
                        }
                        else
                        {
                            txtFrom.Visible = true;
                            txtTo.Visible = true;
                            txtFrom.Text = x.ValueFrom;
                            txtTo.Text = x.ValueTo;
                        }
                    }
                }
            }
            //txtDesc.Text = lblDesc.Text = hdDesc.Value;
            //lblAmt.Text = BUS.CommonControl.Format_Number(Math.Abs(BUS.CommonControl.Format_StringToNumber(hdAmt.Value, "EXA")), "EXA");
            //lblOAmt.Text = BUS.CommonControl.Format_Number(Math.Abs(BUS.CommonControl.Format_StringToNumber(hdAmt.Value, "EXA")), "EXA");
        }



    }
}
